package com.lizi.MarkHsiu;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import com.lizi.core.httpclient.HttpPostTest;

public class LIZIRedisLockTest2 {

	private static AtomicInteger count = new AtomicInteger(0);

	public static void main(String[] args) {
		final String url1 = "http://admin-dev.lizi.com/erp/test";
		final String url2 = "http://192.168.101.21:30020/erp/test";

		ExecutorService pool = Executors.newFixedThreadPool(250);
		long start = System.currentTimeMillis();

		for (int i = 0; i < 1000; i++) {

			final Map<String, String> params = new HashMap<>();
			params.put("id", "1");
			params.put("threadId", count.getAndIncrement()+"");

			Thread t1 = new Thread() {
				public void run() {
					String url = url1;
					if(count.getAndIncrement() % 2 == 0){
						url = url2;
					}
					HttpPostTest.rest(url, params);
				}
			};
			pool.execute(t1);

		}

		pool.shutdown();
		try {
			// 请求关闭、发生超时或者当前线程中断，无论哪一个首先发生之后，都将导致阻塞，直到所有任务完成执行
			// 设置最长等待10秒
			pool.awaitTermination(1000, TimeUnit.SECONDS);
		} catch (InterruptedException e) {
			//
			e.printStackTrace();
		}

		System.out.println(count + " :主线执行。:" + (System.currentTimeMillis() - start));
	}

}
